package com.qj.yantaishan.service.impl;

import com.qj.yantaishan.mapper.UserVoMapper;
import com.qj.yantaishan.service.IUserVoService;
import com.qj.yantaishan.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Primary
public class IUserVoServiceImpl implements IUserVoService {
    @Autowired
    private UserVoMapper userVoMapper;

    @Override
    public Map<String, Object> list(Integer currentPage, Integer pageSize) {
        Map<String, Object> result = new HashMap<>();
        int current = (currentPage - 1) * pageSize;
        int total = userVoMapper.total();
        result.put("current", currentPage);
        result.put("size", pageSize);
        result.put("total", total);
        int pages = (total / pageSize) % 10 == 0 ? (total / pageSize) : (total / pageSize) + 1;
        result.put("pages", pages);
        List<UserVo> records = userVoMapper.userList(current, pageSize);
        result.put("records", records);

        return result;
    }

    @Override
    public void update(Map<String, String> body) {
        String vipId = body.get("ssvId");
        String userId = body.get("uid");
        String isBlack = body.get("isBlack");
        userVoMapper.myUpdate(vipId,userId,isBlack);
    }
}
